package com.diudiutechnology.www.yadiudiu.yadiudiu.mine.MyAdapter;

import android.content.Context;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.diudiutechnology.www.yadiudiu.yadiudiu.mine.MyActivity.MyOrderActivity;
import com.diudiutechnology.www.yadiudiu.yadiudiu.model.BuyACarFragmentModel;
import com.diudiutechnology.www.yadiudiu.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/8/18.
 * 订单
 */

public class MyOrderActivityAdapter  extends BaseAdapter {

    private Context mContext;
    List<BuyACarFragmentModel> model= new ArrayList<>();
    public MyOrderActivityAdapter(Context context) {
        this.mContext = context;
    }

    @Override
    public int getCount() {
        return model.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }
    public void addItem( List<BuyACarFragmentModel> model){
        this.model=model;
        notifyDataSetChanged();
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(mContext).inflate(
                    R.layout.item_my_order, null);
            holder.item_order = (TextView) convertView
                    .findViewById(R.id.item_order);

            holder.item_type = (TextView) convertView
                    .findViewById(R.id.item_type);
            holder.item_lei = (TextView) convertView
                    .findViewById(R.id.item_lei);
            holder.time = (TextView) convertView
                    .findViewById(R.id.time);
            holder.item_moneys = (TextView) convertView
                    .findViewById(R.id.item_moneys);
            holder.prompting = (TextView) convertView
                    .findViewById(R.id.prompting);
            holder.complete_resend_layout = (LinearLayout) convertView
                    .findViewById(R.id.complete_resend_layout);
            holder.complete = (TextView) convertView
                    .findViewById(R.id.complete);
            holder.resend = (TextView) convertView
                    .findViewById(R.id.resend);
            holder.cancel = (TextView) convertView
                    .findViewById(R.id.cancel);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }


        BuyACarFragmentModel bModel = model.get(position);
        holder.item_order.setText(bModel.getName());
        holder.item_type.setText(bModel.getDate());
        holder.item_lei.setText(bModel.getLet());
        holder.time.setText(bModel.getDistance());
        holder.item_moneys.setText(bModel.getMoney1());
        if (bModel.getPraise().equals("0")){
            holder.complete_resend_layout.setVisibility(View.VISIBLE);
            holder.complete.setVisibility(View.VISIBLE);
            holder.resend.setVisibility(View.VISIBLE);
            holder.cancel.setVisibility(View.VISIBLE);
            holder.cancel.setText("删除");
            holder.prompting.setText(Html.fromHtml("<font color='#00BFDE'>已接单</font>"));
        }else  if (bModel.getPraise().equals("1")){
            holder.complete_resend_layout.setVisibility(View.VISIBLE);
            holder.complete.setVisibility(View.INVISIBLE);
            holder.resend.setVisibility(View.INVISIBLE);
            holder.cancel.setVisibility(View.VISIBLE);
            holder.cancel.setText("删除");
            holder.prompting.setText(Html.fromHtml("<font color='#00BFDE'>咨询中</font>"));
        }else  if (bModel.getPraise().equals("2")){
            holder.complete_resend_layout.setVisibility(View.VISIBLE);
            holder.complete.setVisibility(View.INVISIBLE);
            holder.resend.setVisibility(View.INVISIBLE);
            holder.cancel.setVisibility(View.VISIBLE);
            holder.cancel.setText("评论");
            holder.cancel.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    ((MyOrderActivity)mContext).processCommentaries();
                }
            });
            holder.prompting.setText(Html.fromHtml("<font color='#262626'>订单已完成</font>"));
        }else  if (bModel.getPraise().equals("3")){
            holder.complete_resend_layout.setVisibility(View.GONE);
            holder.complete.setVisibility(View.INVISIBLE);
            holder.resend.setVisibility(View.INVISIBLE);
            holder.cancel.setVisibility(View.INVISIBLE);
            holder.prompting.setText(Html.fromHtml("<font color='#262626'>订单已完成</font>"));
        }else  if (bModel.getPraise().equals("4")){
            holder.complete_resend_layout.setVisibility(View.GONE);
            holder.complete.setVisibility(View.INVISIBLE);
            holder.resend.setVisibility(View.INVISIBLE);
            holder.cancel.setVisibility(View.INVISIBLE);
            holder.prompting.setText(Html.fromHtml("<font color='#00BFDE'>等待骑手取衣</font>"));
        }
        return convertView;
    }

    class ViewHolder {
        TextView item_order;
        TextView item_type;
        TextView item_lei;
        TextView time;
        TextView item_moneys;
        TextView prompting;
        LinearLayout complete_resend_layout;
        TextView complete;
        TextView resend;
        TextView cancel;

    }
}


